package kalkon.URLBuilder;

import java.util.Calendar;

/**
 *
 * @author newohybat newohybat@gmail.com
 */
public class URLBuilder {
    private static final String MONTH_TOKEN="MONTHTOKEN";
    private static final String YEAR_TOKEN="YEARTOKEN";
    private int month;
    private int year;

    public URLBuilder(){
        Calendar cal = Calendar.getInstance();
        this.month=cal.get(Calendar.MONTH)+1;
        this.year = cal.get(Calendar.YEAR);
    }
    public URLBuilder(int month,int year){
        this.month=month;
        this.year=year;
    }
    
    /**
     * Expands String template of a URL into URL specific for the month and the year
     * @param input String template to be expanded
     * @return String url in the right form
     */
    public String transform(String input){
        String url=input;
        if(isTransformable(input)){
            String expandedMonth = input.replaceAll(MONTH_TOKEN, Integer.toString(month));
            String expandedYear = expandedMonth.replaceAll(YEAR_TOKEN, Integer.toString(year));
            url=expandedYear;
        }
        return url;
    }
    public boolean isTransformable(String input){
        return input.contains(MONTH_TOKEN)&&input.contains(YEAR_TOKEN);
    }
}
